#include <iostream>
#include <string>

// 被装饰的基类抽象类
class Car
{
public:
    Car() = default;
    Car(const std::string &name) : name(name) {}
    virtual void showInfo() = 0;
protected:
    std::string name;
};

// 被装饰的具体类
class BMW: public Car
{
public:
    using Car::Car;
    void showInfo()
    {
        std::cout << name << std::endl;
    }
};

// 抽象装饰类
class Decorate : public Car
{
public:
    using Car::Car;
    void decorate(Car *c)
    {
        this->c = c;
    }

protected:
    Car *c; // 要装饰的对象
};

// 具体装饰类
class SelfDrive : public Decorate
{
public:
    void showInfo()
    {
        std::cout << "自动驾驶";
        c->showInfo();
    }
};

class Navigator : public Decorate
{
public:
    void showInfo()
    {
        std::cout << "导航";
        c->showInfo();
    }
};

class VoiceControl : public Decorate
{
public:
    void showInfo()
    {
        std::cout << "语音控制";
        c->showInfo();
    }
};


int main()
{
    Car *c = new BMW("宝马");
    c->showInfo();

    Decorate *d1 = new SelfDrive;
    Decorate *d2 = new Navigator;
    Decorate *d3 = new VoiceControl;
    // 连续装饰
    d1->decorate(c); // 装饰
    d2->decorate(d1);
    d3->decorate(d2);

    d1->showInfo();
    d2->showInfo();
    d3->showInfo();

    return 0;
}